/* 3DGo Game
 * Copyright (C) 2008 Roman Hwang, Eugene Melnichek

 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation - version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

/****************************************
Revision History

1.01 2008-05-17 Eugene Melnichek
Added new members to GameEngine class: cameraXAngel, cameraYAngel, mainWindow, m_interfaceTexture
New method for input processing: ProcessInput()

1.00 Roman Hwang
Initial revision
****************************************/

#ifndef _GAMEENGINE_H_
#define _GAMEENGINE_H_

#include "Board.h"
#include "d3dUtility.h"
#include "numericupdown.h"


class Player;

namespace Audio
{
	class AudioPlayer;
}
/*
	Class that run game logic.
*/

class GameEngine
{
	/* Screen params */
	static const int WIDTH = 800;
	static const int HEIGHT = 600;
	static const float DIST_TO_BOARD;// = 4.0f;
	float cameraYAngle;
	float cameraXAngle;
	HWND mainWindow;

	/* Players */
	Player* m_playerWhite;
	Player* m_playerBlack;
	Player* _activePlayer;

	/* Flag is quiting */
	bool _isQuiting;

	int _passCount;

	/* Board */
	Board m_board;

	/* Controls */
	NumericUpDown soundVolume;

	/*Sprite*/
	ID3DXSprite * m_interfaceSprite;
	IDirect3DTexture9 * m_interfaceTexture;

	/* Audio */
	Audio::AudioPlayer* _audioPlayer;

	/*Engine states*/
	bool processInput;

private:

	bool IsGameOver();
	void SwitchPlayer();

	void SetupView();
	void CreateGTPThread();
	void ProcessInput(float delta);
	
	static DWORD ThreadGTP(LPWORD lpData);

public:

	/* Constructor */
	GameEngine( int boardSize );

	/* Destructor */
	~GameEngine();

	/* Run game logic here */
	void Run();

	/* Initialize game */
	void Init(HINSTANCE _hInstance, WNDPROC WndProc);

	/* Draw game objects */
	void Render(float delta);

	/* Engine states */
	void SetProcessInputState(bool process) {processInput = process;}

	/* Message handling */
	bool MouseButtonDown(int x, int y, MouseButtons button);
	bool MouseButtonUp(int x, int y, MouseButtons button);
};

#endif // _GAMEENGINE_H_